using B.S.Data.MES.API.Applications.approve.Command;
using B.S.Domain.Node;
using B.S.Infratrctrue;
using B.S.Requst;
using ICSharpCode.SharpZipLib.Tar;
using MediatR;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace B.S.Data.MES.API.Applications.approve.CommandHandlers
{
    public class GetAllShenPiCommandHandlers : IRequestHandler<GetAllShenPiCommand, APIRequst<List<ShenPiinfo>>>
    {
        private readonly IBaseRepository<ShenPiinfo> shenPiRepository;

        public GetAllShenPiCommandHandlers(IBaseRepository<ShenPiinfo> shenPiRepository)
        {
            this.shenPiRepository = shenPiRepository;
        }

        /// <summary>
        /// 获取所有审批表数据
        /// </summary>
        /// <param name="request">查询请求</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>审批表数据列表</returns>
        public async Task<APIRequst<List<ShenPiinfo>>> Handle(GetAllShenPiCommand request, CancellationToken cancellationToken)
        {
            var allShenPi = shenPiRepository.GetAll().Where(x => x.NetxPersonId == request.UserId);

            return new APIRequst<List<ShenPiinfo>>
            {
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString(),
                Data = allShenPi.ToList()
            };
        }
    }
}